import com.github.odiszapc.nginxparser.NgxBlock;
import com.github.odiszapc.nginxparser.NgxConfig;
import com.github.odiszapc.nginxparser.NgxEntry;
import com.github.odiszapc.nginxparser.NgxParam;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Administrator on 2017/5/10.
 */
public class domain {

    public static void main(String[] a) throws IOException {


        List<String> companys = getUrls("D:\\etc\\nginx\\boot\\domain_list.conf", "company");
        List<String> personals = getUrls("D:\\etc\\nginx\\boot\\domain_list.conf", "personal");
    }

    private static List<String> getUrls(String path, String tag) throws IOException {
        NgxConfig conf = NgxConfig.read(path);
        List<NgxEntry> personals = conf.findAll(NgxConfig.BLOCK, tag);
        List<String> personalUrl = new ArrayList<>();
        for (NgxEntry ngxEntry : personals) {
            if (ngxEntry instanceof NgxBlock) {
                NgxBlock block = (NgxBlock) ngxEntry;
                Iterator<NgxEntry> iterable = block.getEntries().iterator();
                while (iterable.hasNext()) {
                    NgxEntry entry = iterable.next();
                    NgxParam ngxParam = (NgxParam) entry;
                    personalUrl.add(ngxParam.getName());
                }
            }
        }
        return personalUrl;
    }
}
